<?php

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
 	require_once (APPLICATION_PATH . "\\models\\connectionDb.php");
} else {
    require_once (APPLICATION_PATH . "//models//connectionDb.php");
}

class Application_Model_DbTable_Tag extends Zend_Db_Table_Abstract
{

    protected $_name = 'Tag';
    
    public function createTag($term)
    {
    	$data = array('Term' => $term);
    	return  $this->insert($data);	//shtom ke ja vnese stavkata vo bazata, go vrakja id na istata.
    }

	public function getTag($id)
	{
		$id = (int)$id;
		$row = $this->fetchRow("id = '".$id."'");
		return $row['Tag'];
	}
	
	public function getID($term)
	{
		$row = $this->fetchRow("Term = '".$term."'");
		return $row['id'];
	}
	
	public function getAll()
	{	
		$sql  ="select Term ";
     	$sql .=" from Tag";
		$sql .=" where 1=1";
		$sql .=" order by Term desc";  
  		
		$db = connectionDb::connectDB();		
		$rows = $db->fetchAll($sql);
		return $rows;
	}
}

